/**
*	@file QueryTNode.h
*
*	@brief this header defines the query clause as QueryTNode structure
*
*	@author li yuchen
*
*	@date 1/28/2011
*/
#ifndef QUERYTNODE_H
#define QUERYTNODE_H

#include "TNode.h"
#include <string>
using namespace std;

/**	@brief type of query of a query tnode */
enum QueryType{
	/** @brief follows query type */
	FOLLOWS,			 
	FOLLOWS_ADV,          

	/** @brief parent query type */
	PARENT,				 
	PARENT_ADV,			

	/** @brief call query type */
	CALLS,
	CALLS_ADV,

	/** @brief next query type */
	NEXT,
	NEXT_ADV,

	/** @brief affect query type */
	AFFECTS,
	AFFECTS_ADV,

	/** @brief modifies query type */
	MODIFIES,

	/** @brief uses query type */
	USES,

	/** @brief ensure the two query variable have the same result */
	COMPARE,

	/** @brief pattern query type */
	PATTERN_Q,

	/** @brief next query type */
	NEXTBIP,
	NEXTBIP_ADV,

	/** @brief affect query type */
	AFFECTSBIP,
	AFFECTSBIP_ADV,

	/** @brief this type means the query is not valid (don't have result or false) */
	STOP
};

/** @brief return the text representation of the query type */
string QueryTypeToString(QueryType q_type);


/**
*	@brief if it is equal to -1, then the argument is not constraint
*		else if the argument is a variable,the query is also not constraint then it is refer to the index in QueryVarTable
*		if the argument is a constant, then it is the value of the constant
*/
typedef int QueryArgumentValue;

/** @brief lower priority means the query is more easy to evaluate */
typedef int QueryPriority;


struct QueryTNode{
	QueryType q_type;

	/** 
	*	@brief if it is a pattern query, argument_a will set to the var_idx it corresponding to
	*		if it is a root node, it will set to var_idx or to 0 if it is a boolean
	*/
	QueryArgumentValue argument_a;

	/** 
	*	@brief if it is a pattern query, argument_b will set to 0
	*		or the query node belong to root, b will set to 0
	*/
	QueryArgumentValue argument_b;

	/** @brief for pattern query */
	TNode* pattern;

	/** @brief means whether is pattern is strict or relaxed */
	bool isRelaxed;

	/** @brief priority of the query */
	QueryPriority priority;

	/** 
	*	@brief special use for query evaluate when it is a modifies or uses
	*		and the left side is a PROC_TYPE query variable or
	*		a STMT_TYPE query variable, otherwise it will set to OP_TYPE
	*/
	TNodeType special_type;
};


#endif